package com.situ.day2;

import java.util.Random;
import java.util.Scanner;

import javax.swing.text.AbstractDocument.BranchElement;

import org.junit.Test;

public class WhileDemo {
	@Test
	public void test1() {
		//1、循环条件的初始化
		int i = 1;
		//2、循环条件的控制
		while (i <= 5) {
			System.out.println("HelloWorld!");
			//3、循环条件的改变（趋向于循环条件的结束）
			i++;
		}
	}
	
	//1+2+3+...+100=5050
	@Test
	public void test2() {
		int i = 1;
		int sum = 0;
		while (i <= 100) {
			System.out.println(i);
			sum = sum + i;//sum += i;
			i++;
		}
		System.out.println("sum: " + sum);
	}
	
	//1*9=9 2*9=18  3*9=27  4*9=36 ...  8*9=72  9*9=81
	@Test
	public void test44() {
		int i = 1;
		while (i <= 9) {
			System.out.print(i + "*9=" + (i * 9) + "\t");
			i++;
		}
	}
	
	@Test
	public void test33() {
		Random random = new Random();
		int code = random.nextInt(1000);
		Scanner scanner = new Scanner(System.in);
		while (true) {
			System.out.println("猜吧");
			int num = scanner.nextInt();
			if (num > code) {
				System.out.println("太大了");
			} else if (num < code) {
				System.out.println("太小了");
			} else {
				System.out.println("猜对了");
				break;
			}
		}
		System.out.println("end");
	}
	
	@Test
	public void test334() {
		Scanner scanner = new Scanner(System.in);
		int password = 0;
		do {
			System.out.println("请输入密码");
			password = scanner.nextInt();
		} while (password != 123);
	}
	
	
	
}
